<?php
// +----------------------------------------------------------------------
// | ZGUAN [ 致力于帮助更多的中小企业物联网转型 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2024 https://www.zguan.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ZGUAN 并不是自由软件，未经许可不能去掉ZGUAN 相关版权
// +----------------------------------------------------------------------
// | Author: ZGUAN Team <admin@zguan.cn>  0769-82282996 15899929162
// +----------------------------------------------------------------------
namespace app\common\dao\system\sms;

use app\common\dao\BaseDao;
use app\common\model\system\sms\SystemSmsLogModel;

class SystemSmsLogDao extends BaseDao
{

    /**
     * @return SystemSmsLogModel
     */
    protected function getModel(): string
    {
        return SystemSmsLogModel::class;
    }

    public function search(array $where, int $propertyId = null)
    {
        return $this->getModel()::getDB()
            ->when($propertyId !== null, function ($query) use ($propertyId) {
                $query->where('property_id', $propertyId);
            })
            ->when(isset($where['mobile']) && $where['mobile'] !== '', function ($query) use ($where) {
                $query->whereLike('mobile', '%' . trim($where['mobile']) . '%');
            })
            ->when(isset($where['is_verify']) && $where['is_verify'] !== '', function ($query) use ($where) {
                $query->where('is_verify', (int)$where['is_verify']);
            })
            ->when(isset($where['keywords']) && $where['keywords'] !== '', function ($query) use ($where) {
                $query->where('content|error_msg', 'like', '%' . trim($where['keywords']) . '%');
            })
            ->when(isset($where['code']) && $where['code'] !== '', function ($query) use ($where) {
                $query->where('code', $where['code']);
            })
            ->when(isset($where['add_time']) && $where['add_time'] !== '', function ($query) use ($where) {
                $this->timeSearchBuild($query, $where['add_time'], 'add_time');
            });
    }
}
